package hu.blok1.veilingsite.client.gui;

import hu.blok1.veilingsite.client.Veilingsite;
import hu.blok1.veilingsite.shared.User;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;

public class rightMenuGUI {
	private Veilingsite veilingsite;
	private User user;

	private VerticalPanel vp;

	public rightMenuGUI(Veilingsite v) {
		veilingsite = v;
		preinit();
	}
	
	public void preinit(){
		user = veilingsite.getUser();

		vp = veilingsite.getRightMenu();
		vp.clear();

		vp.setSpacing(10);

		if (user.isLoggedIn()) {
			init();
		} else {
			Hyperlink login = new Hyperlink("Log in", "login");
			vp.add(login);
		}
	}

	public void init() {
		FlexTable flexOne = new FlexTable();
		
		Hyperlink personalPage = new Hyperlink(user.getName(), "personalPage");
		flexOne.setText(0, 0, "Welkom ");
		flexOne.setWidget(0, 1, personalPage);
		flexOne.setText(1, 0, "Aantal Credits: ");
		flexOne.setText(1, 1, "" + user.getCredits());
		flexOne.setText(2, 0, "Credits kopen: ");
		flexOne.setWidget(2, 1, new Hyperlink("Koopkoopkoop", "home"));
		vp.add(flexOne);
	}

	public void reload() {
		preinit();
	}
}
